package com.example.crawler.job;

import com.example.crawler.model.Img;
import com.example.crawler.repository.ImgRepository;
import com.example.crawler.service.ImgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Queue;

/**
 * @Description
 * @Date 2022/11/1 19:39
 * @Author pq
 */
@Component
@Slf4j
public class ImgTask {

    @Resource
    private ImgService imgService;

    @Resource
    private ImgRepository imgRepository;

//    @Scheduled(cron = "0/1 * * * * ? ")
//    private void saveImg() {
//        for (int j = 0; j < 100; j++) {
//            Img img = new Img();
//            Queue<String> imgUrls=imgService.getImgUrlQueue();
//            img.setUrl(imgUrls.poll());
//            imgRepository.save(img);
//            System.out.println("图片保存成功，目前队列大小："+imgUrls.size());
//        }
//    }
}
